clear all 
use "data\out\estsample.dta", clear
g byte PeakxEvent = Peak*EventDay
g byte ShoulderxEvent = shoulder*EventDay

merge m:1 maalepktnr using "data\in\surveydata2.dta", keep(master match) keepusing(Hvormangepersonerbordetidi Hvaerdinhøyestfullførteutda) 
g byte surveyresponse = 0
foreach y of varlist Hvormangepersonerbordetidi Hvaerdinhøyestfullførteutda {
	replace surveyresponse = 1 if `y' != ""
}

ivreghdfe lnforbruk c.temp##c.temp##c.temp temp_* Peak PeakxEvent ShoulderxEvent Peakelcar shoulder shoulderelcar ///
  (Effektpris EffektprisNonPeak Effektprisnext EffektprisNonPeaknext Effektpriselcar EffektprisNonPeakelcar Effektprisnextelcar EffektprisNonPeaknextelcar Effektprisshoulder Effektprisshoulderelcar =  TPE TNPE TPnextdays TNPnextdays TPEelcar TNPEelcar TPnextdayselcar TNPnextdayselcar TsE TsEelcar) if surveyresponse == 1, absorb(maalepktnr dato) cluster(maalepktnr)
est store IV5_survey 
estadd ysumm  

ivreghdfe lnforbruk c.temp##c.temp##c.temp temp_* Peak PeakxEvent ShoulderxEvent Peakelcar shoulder shoulderelcar ///
  (Effektpris EffektprisNonPeak Effektprisnext EffektprisNonPeaknext Effektpriselcar EffektprisNonPeakelcar Effektprisnextelcar EffektprisNonPeaknextelcar Effektprisshoulder Effektprisshoulderelcar =  TPE TNPE TPnextdays TNPnextdays TPEelcar TNPEelcar TPnextdayselcar TNPnextdayselcar TsE TsEelcar) if surveyresponse == 0, absorb(maalepktnr dato) cluster(maalepktnr)
est store IV5_nosurvey 
estadd ysumm  

estout IV5_survey IV5_nosurvey using "output\table_C2.txt", replace type ///
  cells(b( fmt(3)) se(par fmt(3)) _star) indicate(temp) ///mlabels(1 2 3 4 5 6 ) collabels(none) legend ///
  order(Effektpris EffektprisNonPeak Effektprisnext EffektprisNonPeaknext Peak PeakxEvent ShoulderxEvent Effektpriselcar EffektprisNonPeakelcar Effektprisnextelcar EffektprisNonPeaknextelcar Peakelcar Effektprisshoulder shoulder Effektprisshoulderelcar shoulderelcar) ///
  varlabels(TPE TP TNPE TNP) starlevels(* 0.10 ** 0.05 *** 0.01) varwidth(26) ///
  stats(ymean r2 N, fmt(3 3 0 0)) style(tex)

  
  
